home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Mania 4
/
MacMania 4.toast
/
/
Demo's
/
Igor Demo Pro
/
1 PutContentsIn Igor Pro Folder
/
WaveMetrics Procedures
/
Math Functions
/
AreaXY
next >
Wrap
Text File
|
1996-04-01
|
2KB
|
66 lines
#include <BinarySearch>
| AreaXY 1.2
| v1.2 - corrected end-of-range code for IGOR Pro 3.01
| v1.1 - Igor Pro version 2.05 fixes a bug with a or b at first or last point in wave,
| and limits the range to a valid range if a or b are before or after the
| first and last points in the wave.
|
| Given a tabulated function with monotonically increasing or decreasing
| x values, AreaXY returns the trapezoidal area over an interval.
|
Function/D AreaXY(xwave,ywave,a,b)
Wave/D xwave,ywave | xwave must be monotonic!
Variable/D a,b | limits of integration
variable n= numpnts(xwave),tmp
variable/D increasing= xwave[n-1] > xwave[0],reversed=0
if( increasing )
if( a > b )
tmp= a
a= b
b= tmp
reversed= 1
endif
else
if( a < b )
tmp= a
a= b
b= tmp
reversed= 1
endif
endif
variable/D pa=BinarySearch(xwave,a),pb=BinarySearch(xwave,b)
if( pa < 0 )
pa= 0
a= xwave[pa]
endif
if( pb < 0 )
pb= n-1
b= xwave[pb]
endif
pb += 1
| now we know that a and b are somewhere between xwave[pa] and xwave[pb] inclusive
variable/D f= (xwave[pa+1]-a)/(xwave[pa+1]-xwave[pa])
variable/D y= f*ywave[pa]+(1-f)*ywave[pa+1] | interpolated y at a
variable/D area= (y+ywave[pa+1])*(xwave[pa+1]-a)/2 | area from a to next point
do
pa += 1
if( pa >= pb )
break;
endif
area += (ywave[pa]+ywave[pa+1])*(xwave[pa+1]-xwave[pa])/2
while(1)
if( pb != n )
f= (xwave[pb]-b)/(xwave[pb]-xwave[pb-1])
y= f*ywave[pb-1]+(1-f)*ywave[pb] | interpolated y at b
area -= (y+ywave[pb])*(xwave[pb]-b)/2 | correct for area from b to last point
endif
if(reversed)
return -area
endif
return area
End